package com.example.day19_7_19_1.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.example.day19_7_19_1.R;

import org.greenrobot.eventbus.EventBus;

public abstract class BaseFragment<P extends BasePresenter> extends Fragment implements BaseView {
    public P iPresenter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(getLayout(), container, false);
        iPresenter = initPresenter();
        if (iPresenter != null){
            iPresenter.bindView(this);
        }
        EventBus.getDefault().register(this);
        initView(view);
        initData();
        return view;
    }

    protected abstract P initPresenter();

    protected abstract void initData();

    protected abstract void initView(View view);

    protected abstract int getLayout();

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
